<!--#include file="./load.inc"-->
<%
Dim checkCode
Set checkCode = New codeModel
checkCode.checkCode

Class codeModel
	Private nMaxSaturation, nBlankNoisyDotOdds, nColorNoisyDotOdds, nCharCount, nPixelWidth
	Private nPixelHeight, nColorHue, nAngleRandom, nLengthRandom, cCharSet
	Private CursorX, CursorY, DirX, DirY, Buf(), DigtalStr, Lines(), LineCount

	private sub class_initialize()
		nMaxSaturation = 200	'最大色彩饱和度
		nBlankNoisyDotOdds = 0.2	'空白处噪点率
		nColorNoisyDotOdds = 0.1	'有色处噪点率
		nCharCount = checkAmount	'产生的字符个数
		nPixelWidth = 26	'单个字符位图的宽度
		nPixelHeight = 30	'单个字符位图的高度
		nColorHue = -1	'显示验证码的色调(-1表示随机色调, -2表示灰度色调)'220
		nAngleRandom = 10	'角度随机量
		nLengthRandom = 30	'长度随机量(百分比)
		cCharSet = "0123456789" '0123456789构成验证码的字符集
	End sub

	Private Function header()
	    Response.Expires = -1
        Response.AddHeader "pragma", "no-cache"
        Response.AddHeader "cache-ctrol", "no-cache"
        Response.ContentType = "image/png"
	End Function

	Public Function checkCode()
		Dim I, J, CurColorHue
		Dim PicWidth, PicHeight, FileSize, PicDataSize
		'禁止缓存
        Call header
		Call CDGen
		session(cacheName) = lcase(DigtalStr)	'记录入Session
		PicWidth = nCharCount * nPixelWidth
		PicHeight = nPixelHeight
		PicDataSize = PicWidth * PicHeight * 3
		FileSize = PicDataSize + 54
		'输出BMP文件信息头
		Response.BinaryWrite ChrB(66) & ChrB(77) &_
		ChrB(FileSize Mod 256) & ChrB((FileSize \ 256) Mod 256) & ChrB((FileSize \ 256 \ 256) Mod 256) & ChrB(FileSize \ 256 \ 256 \ 256) &_
		ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0) &_
		ChrB(54) & ChrB(0) & ChrB(0) & ChrB(0)
		'输出BMP位图信息头
		Response.BinaryWrite ChrB(40) & ChrB(0) & ChrB(0) & ChrB(0) &_
		ChrB(PicWidth Mod 256) & ChrB((PicWidth \ 256) Mod 256) & ChrB((PicWidth \ 256 \ 256) Mod 256) & ChrB(PicWidth \ 256 \ 256 \ 256) &_
		ChrB(PicHeight Mod 256) & ChrB((PicHeight \ 256) Mod 256) & ChrB((PicHeight \ 256 \ 256) Mod 256) & ChrB(PicHeight \ 256 \ 256 \ 256) &_
		ChrB(1) & ChrB(0) &_
		ChrB(24) & ChrB(0) &_
		ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0) &_
		ChrB(PicDataSize Mod 256) & ChrB((PicDataSize \ 256) Mod 256) & ChrB((PicDataSize \ 256 \ 256) Mod 256) & ChrB(PicDataSize \ 256 \ 256 \ 256) &_
		ChrB(18) & ChrB(11) & ChrB(0) & ChrB(0) &_
		ChrB(18) & ChrB(11) & ChrB(0) & ChrB(0) &_
		ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0) &_
		ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0)
		'逐点输出位图阵列
		If nColorHue = -1 Then
			CurColorHue = Int(Rnd * 360)
		ElseIf nColorHue = -2 Then
			CurColorHue = 0
		Else
			CurColorHue = nColorHue
		End If
		For J = 0 To nPixelHeight - 1
			For I = 0 To Len(DigtalStr) * nPixelWidth - 1
				If nColorHue = -2 Then
					Response.BinaryWrite HSBToRGB(CurColorHue, 0, 100 - Buf(nPixelHeight - 1 - J, I))
				Else
					Response.BinaryWrite HSBToRGB(CurColorHue, Buf(nPixelHeight - 1 - J, I), 100)
				End If
			Next
		Next
	End Function

	Public Function checkCode2()
		Const cOdds = 3 ' 杂点出现的机率
		cCharSet = "0123456789"
		Call header
		randomize
		dim i, ii, iii, CodeLen, vCodes, BakColor(1), RanChk(10), CodeColor(10), ChkNum(9)
		CodeLen = app.int1(checkAmount)
		RanChk(0) = ChrB(150) & ChrB(0) & ChrB(0)
		RanChk(1) = ChrB(0) & ChrB(150) & ChrB(0)
		RanChk(2) = ChrB(0) & ChrB(0) & ChrB(150)
		RanChk(3) = ChrB(0) & ChrB(50) & ChrB(150)
		RanChk(4) = ChrB(150) & ChrB(50) & ChrB(0)
		RanChk(5) = ChrB(150) & ChrB(0) & ChrB(150)
		RanChk(6) = ChrB(150) & ChrB(100) & ChrB(10)
		RanChk(7) = ChrB(150) & ChrB(40) & ChrB(120)
		RanChk(8) = ChrB(150) & ChrB(0) & ChrB(250)
		RanChk(9) = ChrB(100) & ChrB(100) & ChrB(100)
		BakColor(0) = RanChk(9 * Rnd)
		BakColor(1) = ChrB(255) & ChrB(255) & ChrB(255)
		redim vCode(CodeLen - 1)
		for i = 0 to CodeLen - 1
			vCode(i) = mid(cCharSet, fix(len(cCharSet) * Rnd) + 1, 1)
			CodeColor(i) = RanChk(vCode(i))
			vCodes = vCodes & vCode(i)
		next
		session(cacheName) = lcase(vCodes)
		ChkNum(0) = "1110000111110111101111011110111101001011110100101111010010111101001011110111101111011110111110000111"
		ChkNum(1) = "1111011111110001111111110111111111011111111101111111110111111111011111111101111111110111111100000111"
		ChkNum(2) = "1110000111110111101111011110111111111011111111011111111011111111011111111011111111011110111100000011"
		ChkNum(3) = "1110000111110111101111011110111111110111111100111111111101111111111011110111101111011110111110000111"
		ChkNum(4) = "1111101111111110111111110011111110101111110110111111011011111100000011111110111111111011111111000011"
		ChkNum(5) = "1100000011110111111111011111111101000111110011101111111110111111111011110111101111011110111110000111"
		ChkNum(6) = "1111000111111011101111011111111101111111110100011111001110111101111011110111101111011110111110000111"
		ChkNum(7) = "1100000011110111011111011101111111101111111110111111110111111111011111111101111111110111111111011111"
		ChkNum(8) = "1110000111110111101111011110111101111011111000011111101101111101111011110111101111011110111110000111"
		ChkNum(9) = "1110001111110111011111011110111101111011110111001111100010111111111011111111101111011101111110001111"
		response.BinaryWrite ChrB(66) & ChrB(77) & ChrB(166) & ChrB(4) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0) &_
		ChrB(0) & ChrB(54) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(40) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(CodeLen*10) & ChrB(0) &_
		ChrB(0) & ChrB(0) & ChrB(10) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(1) & ChrB(0)
		response.BinaryWrite ChrB(24) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(176) & ChrB(4) & ChrB(0) &_
		ChrB(0) & ChrB(18) & ChrB(11) & ChrB(0) & ChrB(0) & ChrB(18) & ChrB(11) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0) &_
		ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0)
		for i = 9 to 0 Step - 1
			for ii = 0 to CodeLen - 1
				for iii = 1 to 10
					BakColor(0) = CodeColor(ii)
					if Rnd * 99 + 1 < cOdds then
						response.BinaryWrite BakColor(0)
					else
						response.BinaryWrite BakColor(mid(ChkNum(vCode(ii)), i * 10 + iii, 1))
					end if
				next
			next
		next
	End Function

	Private Function CDGen_Reset()
		'复位矢量笔和环境变量
		LineCount = 0
		CursorX = 0
		CursorY = 0
		'初始的光笔方向是垂直向下
		DirX = 0
		DirY = 1
	End Function
	Private Function CDGen_Clear()
		'清空位图阵列
		Dim I, J
		ReDim Buf(nPixelHeight - 1, nCharCount * nPixelWidth - 1)
		For J = 0 To nPixelHeight - 1
			For I = 0 To nCharCount * nPixelWidth - 1
				Buf(J, I) = 0
			Next
		Next
	End Function
	Private Function CDGen_PSet(X, Y)
		'在位图阵列上画点
		Buf(Y, X) = 1
	End Function
	Private Function CDGen_Line(X1, Y1, X2, Y2)
		'在位图阵列上画线
		Dim DX, DY, DeltaT, I
		DX = X2 - X1
		DY = Y2 - Y1
		If Abs(DX) > Abs(DY) Then DeltaT = Abs(DX) Else DeltaT = Abs(DY)
		For I = 0 To DeltaT
			CDGen_PSet X1 + DX * I / DeltaT, Y1 + DY * I / DeltaT
		Next
	End Function
	Private Function CDGen_FowardDraw(nLength)
		'按当前光笔方向绘制指定长度并移动光笔，正数表示从左向右/从上向下绘制，负数表示从右向左/从下向上绘制
		nLength = Sgn(nLength) * Abs(nLength) * (1 - nLengthRandom / 100 + Rnd * nLengthRandom * 2 / 100)
		ReDim Preserve Lines(3, LineCount)
		Lines(0, LineCount) = CursorX
		Lines(1, LineCount) = CursorY
		CursorX = CursorX + DirX * nLength
		CursorY = CursorY + DirY * nLength
		Lines(2, LineCount) = CursorX
		Lines(3, LineCount) = CursorY
		LineCount = LineCount + 1
	End Function
	Private Function CDGen_SetDirection(nAngle)
		'按指定角度设定画笔方向, 正数表示相对当前方向顺时针改变方向，负数表示相对当前方向逆时针改变方向
		Dim DX, DY
		nAngle = Sgn(nAngle) * (Abs(nAngle) - nAngleRandom + Rnd * nAngleRandom * 2) / 180 * 3.1415926
		DX = DirX
		DY = DirY
		DirX = DX * Cos(nAngle) - DY * Sin(nAngle)
		DirY = DX * Sin(nAngle) + DY * Cos(nAngle)
	End Function
	Function CDGen_SetDirectionFormZero(nAngle)
        '按指定角度设定画笔方向，与CDGen_SetDirection的区别是以0度为基准
        nAngle = Sgn(nAngle) * (Abs(nAngle) - nAngleRandom + Rnd * nAngleRandom * 2) / 180 * 3.1415926
        DirX = - Sin(nAngle)
        DirY = Cos(nAngle)
    End Function
	Private Function CDGen_MoveToMiddle(nActionIndex, nPercent)
		'将画笔光标移动到指定动作的中间点上，nPercent为中间位置的百分比
		Dim DeltaX, DeltaY
		DeltaX = Lines(2, nActionIndex) - Lines(0, nActionIndex)
		DeltaY = Lines(3, nActionIndex) - Lines(1, nActionIndex)
		CursorX = Lines(0, nActionIndex) + Sgn(DeltaX) * Abs(DeltaX) * nPercent / 100
		CursorY = Lines(1, nActionIndex) + Sgn(DeltaY) * Abs(DeltaY) * nPercent / 100
	End Function
	Private Function CDGen_MoveCursor(nActionIndex)
		'将画笔光标移动到指定动作的起始点上
		CursorX = Lines(0, nActionIndex)
		CursorY = Lines(1, nActionIndex)
	End Function
	Private Function CDGen_Close(nActionIndex)
		'将当前光笔位置与指定动作的起始点闭合并移动光笔
		ReDim Preserve Lines(3, LineCount)
		Lines(0, LineCount) = CursorX
		Lines(1, LineCount) = CursorY
		CursorX = Lines(0, nActionIndex)
		CursorY = Lines(1, nActionIndex)
		Lines(2, LineCount) = CursorX
		Lines(3, LineCount) = CursorY
		LineCount = LineCount + 1
	End Function
	Private Function CDGen_CloseToMiddle(nActionIndex, nPercent)
		'将当前光笔位置与指定动作的中间点闭合并移动光笔，nPercent为中间位置的百分比
		Dim DeltaX, DeltaY
		ReDim Preserve Lines(3, LineCount)
		Lines(0, LineCount) = CursorX
		Lines(1, LineCount) = CursorY
		DeltaX = Lines(2, nActionIndex) - Lines(0, nActionIndex)
		DeltaY = Lines(3, nActionIndex) - Lines(1, nActionIndex)
		CursorX = Lines(0, nActionIndex) + Sgn(DeltaX) * Abs(DeltaX) * nPercent / 100
		CursorY = Lines(1, nActionIndex) + Sgn(DeltaY) * Abs(DeltaY) * nPercent / 100
		Lines(2, LineCount) = CursorX
		Lines(3, LineCount) = CursorY
		LineCount = LineCount + 1
	End Function
	Private Function CDGen_Flush(X0, Y0)
		'按照当前的画笔动作序列绘制位图点阵
		Dim MaxX, MinX, MaxY, MinY
		Dim DeltaX, DeltaY, StepX, StepY, OffsetX, OffsetY
		Dim I
		MaxX = MinX = MaxY = MinY = 0
		For I = 0 To LineCount - 1
			If MaxX < Lines(0, I) Then MaxX = Lines(0, I)
			If MaxX < Lines(2, I) Then MaxX = Lines(2, I)
			If MinX > Lines(0, I) Then MinX = Lines(0, I)
			If MinX > Lines(2, I) Then MinX = Lines(2, I)
			If MaxY < Lines(1, I) Then MaxY = Lines(1, I)
			If MaxY < Lines(3, I) Then MaxY = Lines(3, I)
			If MinY > Lines(1, I) Then MinY = Lines(1, I)
			If MinY > Lines(3, I) Then MinY = Lines(3, I)
		Next
		DeltaX = MaxX - MinX
		DeltaY = MaxY - MinY
		If DeltaX = 0 Then DeltaX = 1
		If DeltaY = 0 Then DeltaY = 1
		MaxX = MinX
		MaxY = MinY
		If DeltaX > DeltaY Then
			StepX =(nPixelWidth - 2) / DeltaX
			StepY =(nPixelHeight - 2) / DeltaX
			OffsetX = 0
			OffsetY =(DeltaX - DeltaY) / 2
		Else
			StepX =(nPixelWidth - 2) / DeltaY
			StepY =(nPixelHeight - 2) / DeltaY
			OffsetX =(DeltaY - DeltaX) / 2
			OffsetY = 0
		End If
		For I = 0 To LineCount - 1
			Lines(0, I) = Round((Lines(0, I) - MaxX + OffsetX) * StepX, 0)
			If Lines(0, I) < 0 Then Lines(0, I) = 0
			If Lines(0, I) >= nPixelWidth - 2 Then Lines(0, I) = nPixelWidth - 3
			Lines(1, I) = Round((Lines(1, I) - MaxY + OffsetY) * StepY, 0)
			If Lines(1, I) < 0 Then Lines(1, I) = 0
			If Lines(1, I) >= nPixelHeight - 2 Then Lines(1, I) = nPixelHeight - 3
			Lines(2, I) = Round((Lines(2, I) - MinX + OffsetX) * StepX, 0)
			If Lines(2, I) < 0 Then Lines(2, I) = 0
			If Lines(2, I) >= nPixelWidth - 2 Then Lines(2, I) = nPixelWidth - 3
			Lines(3, I) = Round((Lines(3, I) - MinY + OffsetY) * StepY, 0)
			If Lines(3, I) < 0 Then Lines(3, I) = 0
			If Lines(3, I) >= nPixelHeight - 2 Then Lines(3, I) = nPixelHeight - 3
			CDGen_Line Lines(0, I) + X0 + 1, Lines(1, I) + Y0 + 1, Lines(2, I) + X0 + 1, Lines(3, I) + Y0 + 1
		Next
	End Function
	Private Function CDGen_Char(cChar, X0, Y0)
		'在指定坐标处生成指定字符的位图阵列
		CDGen_Reset
		Select Case ucase(cChar)
			Case "0"
				CDGen_SetDirection - 60	'逆时针60度(相对于垂直线)
				CDGen_FowardDraw - 0.7	'反方向绘制0.7个单位
				CDGen_SetDirection - 60	'逆时针60度
				CDGen_FowardDraw - 0.7	'反方向绘制0.7个单位
				CDGen_SetDirection 120	'顺时针120度
				CDGen_FowardDraw 1.5	'绘制1.5个单位
				CDGen_SetDirection - 60	'逆时针60度
				CDGen_FowardDraw 0.7	'绘制0.7个单位
				CDGen_SetDirection - 60	'顺时针120度
				CDGen_FowardDraw 0.7	'绘制0.7个单位
				CDGen_Close 0	'封闭当前笔与第0笔(0开始)
			Case "1"
				CDGen_SetDirection - 90	'逆时针90度(相对于垂直线)
				CDGen_FowardDraw 0.5	'绘制0.5个单位
				CDGen_MoveToMiddle 0, 50	'移动画笔的位置到第0笔(0开始)的50%处
				CDGen_SetDirection 90	'逆时针90度
				CDGen_FowardDraw - 1.4	'反方向绘制1.4个单位
				CDGen_SetDirection 30	'逆时针30度
				CDGen_FowardDraw 0.4	'绘制0.4个单位
			Case "2"
				CDGen_SetDirection 45	'顺时针45度(相对于垂直线)
				CDGen_FowardDraw - 0.7	'反方向绘制0.7个单位
				CDGen_SetDirection - 120	'逆时针120度
				CDGen_FowardDraw 0.4	'绘制0.4个单位
				CDGen_SetDirection 60	'顺时针60度
				CDGen_FowardDraw 0.6	'绘制0.6个单位
				CDGen_SetDirection 60	'顺时针60度
				CDGen_FowardDraw 1.6	'绘制1.6个单位
				CDGen_SetDirection - 135	'逆时针135度
				CDGen_FowardDraw 1.0	'绘制1.0个单位
			Case "3"
				CDGen_SetDirection - 90	'逆时针90度(相对于垂直线)
				CDGen_FowardDraw 0.8	'绘制0.8个单位
				CDGen_SetDirection 135	'顺时针135度
				CDGen_FowardDraw 0.8	'绘制0.8个单位
				CDGen_SetDirection - 120	'逆时针120度
				CDGen_FowardDraw 0.6	'绘制0.6个单位
				CDGen_SetDirection 80	'顺时针80度
				CDGen_FowardDraw 0.5	'绘制0.5个单位
				CDGen_SetDirection 60	'顺时针60度
				CDGen_FowardDraw 0.5	'绘制0.5个单位
				CDGen_SetDirection 60	'顺时针60度
				CDGen_FowardDraw 0.5	'绘制0.5个单位
			Case "4"
				CDGen_SetDirection 20	'顺时针20度(相对于垂直线)
				CDGen_FowardDraw 0.8	'绘制0.8个单位
				CDGen_SetDirection - 110	'逆时针110度
				CDGen_FowardDraw 1.2	'绘制1.2个单位
				CDGen_MoveToMiddle 1, 60	'移动画笔的位置到第1笔(0开始)的60%处
				CDGen_SetDirection 90	'顺时针90度
				CDGen_FowardDraw 0.7	'绘制0.7个单位
				CDGen_MoveCursor 2	'移动画笔到第2笔(0开始)的开始处
				CDGen_FowardDraw - 1.5	'反方向绘制1.5个单位
			Case "5"
				CDGen_SetDirection 90	'顺时针90度(相对于垂直线)
				CDGen_FowardDraw 1.0	'绘制1.0个单位
				CDGen_SetDirection - 90	'逆时针90度
				CDGen_FowardDraw 0.8	'绘制0.8个单位
				CDGen_SetDirection - 90	'逆时针90度
				CDGen_FowardDraw 0.8	'绘制0.8个单位
				CDGen_SetDirection 30	'顺时针30度
				CDGen_FowardDraw 0.4	'绘制0.4个单位
				CDGen_SetDirection 60	'顺时针60度
				CDGen_FowardDraw 0.4	'绘制0.4个单位
				CDGen_SetDirection 30	'顺时针30度
				CDGen_FowardDraw 0.5	'绘制0.5个单位
				CDGen_SetDirection 60	'顺时针60度
				CDGen_FowardDraw 0.8	'绘制0.8个单位
			Case "6"
				CDGen_SetDirection - 60	'逆时针60度(相对于垂直线)
				CDGen_FowardDraw - 0.7	'反方向绘制0.7个单位
				CDGen_SetDirection - 60	'逆时针60度
				CDGen_FowardDraw - 0.7	'反方向绘制0.7个单位
				CDGen_SetDirection 120	'顺时针120度
				CDGen_FowardDraw 1.5	'绘制1.5个单位
				CDGen_SetDirection 120	'顺时针120度
				CDGen_FowardDraw - 0.7	'反方向绘制0.7个单位
				CDGen_SetDirection 120	'顺时针120度
				CDGen_FowardDraw 0.7	'绘制0.7个单位
				CDGen_SetDirection 120	'顺时针120度
				CDGen_FowardDraw - 0.7	'反方向绘制0.7个单位
				CDGen_SetDirection 120	'顺时针120度
				CDGen_FowardDraw 0.5	'绘制0.5个单位
				CDGen_CloseToMiddle 2, 50	'将当前画笔位置与第2笔(0开始)的50%处封闭
			Case "7"
				CDGen_SetDirection 180	'顺时针180度(相对于垂直线)
				CDGen_FowardDraw 0.3	'绘制0.3个单位
				CDGen_SetDirection 90	'顺时针90度
				CDGen_FowardDraw 0.9	'绘制0.9个单位
				CDGen_SetDirection 120	'顺时针120度
				CDGen_FowardDraw 1.3	'绘制1.3个单位
			Case "8"
				CDGen_SetDirection - 60	'逆时针60度(相对于垂直线)
				CDGen_FowardDraw - 0.8	'反方向绘制0.8个单位
				CDGen_SetDirection - 60	'逆时针60度
				CDGen_FowardDraw - 0.8	'反方向绘制0.8个单位
				CDGen_SetDirection 120	'顺时针120度
				CDGen_FowardDraw 0.8	'绘制0.8个单位
				CDGen_SetDirection 110	'顺时针110度
				CDGen_FowardDraw - 1.5	'反方向绘制1.5个单位
				CDGen_SetDirection - 110	'逆时针110度
				CDGen_FowardDraw 0.9	'绘制0.9个单位
				CDGen_SetDirection 60	'顺时针60度
				CDGen_FowardDraw 0.8	'绘制0.8个单位
				CDGen_SetDirection 60	'顺时针60度
				CDGen_FowardDraw 0.8	'绘制0.8个单位
				CDGen_SetDirection 60	'顺时针60度
				CDGen_FowardDraw 0.9	'绘制0.9个单位
				CDGen_SetDirection 70	'顺时针70度
				CDGen_FowardDraw 1.5	'绘制1.5个单位
				CDGen_Close 0	'封闭当前笔与第0笔(0开始)
			Case "9"
				CDGen_SetDirection 120	'逆时针60度(相对于垂直线)
				CDGen_FowardDraw - 0.7	'反方向绘制0.7个单位
				CDGen_SetDirection - 60	'逆时针60度
				CDGen_FowardDraw - 0.7	'反方向绘制0.7个单位
				CDGen_SetDirection - 60	'顺时针120度
				CDGen_FowardDraw - 1.5	'绘制1.5个单位
				CDGen_SetDirection - 60	'顺时针120度
				CDGen_FowardDraw - 0.7	'反方向绘制0.7个单位
				CDGen_SetDirection - 60	'顺时针120度
				CDGen_FowardDraw - 0.7	'绘制0.7个单位
				CDGen_SetDirection 120	'顺时针120度
				CDGen_FowardDraw 0.7	'反方向绘制0.7个单位
				CDGen_SetDirection - 60	'顺时针120度
				CDGen_FowardDraw 0.5	'绘制0.5个单位
				CDGen_CloseToMiddle 2, 50	'将当前画笔位置与第2笔(0开始)的50%处封闭
			'以下为字母的矢量动作，有兴趣的可以继续
			Case "A"
				CDGen_SetDirection - (Rnd * 20 + 150)	'逆时针150-170度(相对于垂直线)
				CDGen_FowardDraw Rnd * 0.2 + 1.1	'绘制1.1-1.3个单位
				CDGen_SetDirection Rnd * 20 + 140	'顺时针140-160度
				CDGen_FowardDraw Rnd * 0.2 + 1.1	'绘制1.1-1.3个单位
				CDGen_MoveToMiddle 0, 30	'移动画笔的位置到第1笔(0开始)的30%处
				CDGen_CloseToMiddle 1, 70	'将当前画笔位置与第1笔(0开始)的70%处封闭
			Case "B"
				CDGen_SetDirection - (Rnd * 20 + 50)	'逆时针50-70度(相对于垂直线)
				CDGen_FowardDraw Rnd * 0.4 + 0.8	'绘制0.8-1.2个单位
				CDGen_SetDirection Rnd * 20 + 110	'顺时针110-130度
				CDGen_FowardDraw Rnd * 0.2 + 0.6	'绘制0.6-0.8个单位
				CDGen_SetDirection - (Rnd * 20 + 110)	'逆时针110-130度
				CDGen_FowardDraw Rnd * 0.2 + 0.6	'绘制0.6-0.8个单位
				CDGen_SetDirection Rnd * 20 + 110	'顺时针110-130度
				CDGen_FowardDraw Rnd * 0.4 + 0.8	'绘制0.8-1.2个单位
				CDGen_Close 0	'封闭当前笔与第1笔(0开始)
			Case "C"
				CDGen_SetDirection - 60	'逆时针60度(相对于垂直线)
				CDGen_FowardDraw - 0.7	'反方向绘制0.7个单位
				CDGen_SetDirection - 60	'逆时针60度
				CDGen_FowardDraw - 0.7	'反方向绘制0.7个单位
				CDGen_SetDirection 120	'顺时针120度
				CDGen_FowardDraw 1.5	'绘制1.5个单位
				CDGen_SetDirection 120	'顺时针120度
				CDGen_FowardDraw - 0.7	'反方向绘制0.7个单位
				CDGen_SetDirection 120	'顺时针120度
				CDGen_FowardDraw 0.7	'绘制0.7个单位
            Case "D"
                CDGen_SetDirection - (Rnd * 20 + 50)    '逆时针50-70度(相对于垂直线)
                CDGen_FowardDraw Rnd * 0.4 + 0.8    '绘制0.8-1.2个单位
                CDGen_SetDirection Rnd * 20 + 110    '顺时针110-130度
                CDGen_FowardDraw Rnd * 0.2 + 0.6    '绘制0.6-0.8个单位
                CDGen_FowardDraw Rnd * 0.2 + 0.6    '绘制0.6-0.8个单位
                CDGen_SetDirection Rnd * 20 + 110    '顺时针110-130度
                CDGen_FowardDraw Rnd * 0.4 + 0.8    '绘制0.8-1.2个单位
                CDGen_Close 0    '封闭当前笔与第1笔(0开始)
            Case "E"
                CDGen_SetDirection - (Rnd * 20 - 10)
                CDGen_FowardDraw 1
                CDGen_MoveToMiddle 0, 0
                CDGen_SetDirectionFormZero - (110 - Rnd * 40)
                CDGen_FowardDraw 0.7
                CDGen_MoveToMiddle 0, 50
                CDGen_SetDirectionFormZero - (110 - Rnd * 40)
                CDGen_FowardDraw 0.5
                CDGen_MoveToMiddle 0, 100
                CDGen_SetDirectionFormZero - (110 - Rnd * 40)
                CDGen_FowardDraw 0.9
            Case "F"
                CDGen_SetDirection - (Rnd * 20 - 10)
                CDGen_FowardDraw 1
                CDGen_MoveToMiddle 0, 0
                CDGen_SetDirectionFormZero - (110 - Rnd * 40)
                CDGen_FowardDraw 0.7
                CDGen_MoveToMiddle 0, 50
                CDGen_SetDirectionFormZero - (110 - Rnd * 40)
                CDGen_FowardDraw 0.5
            Case "G"
                CDGen_SetDirection - 60
                CDGen_FowardDraw - 0.7
                CDGen_SetDirection - 60
                CDGen_FowardDraw - 0.7
                CDGen_SetDirection 120
                CDGen_FowardDraw 1.5
                CDGen_SetDirection 120
                CDGen_FowardDraw - 0.7
                CDGen_SetDirection 120
                CDGen_FowardDraw 0.7
                CDGen_SetDirection - 60
                CDGen_FowardDraw 0.5
                CDGen_SetDirection 90
                CDGen_FowardDraw 0.4
                CDGen_MoveToMiddle 6, 0
                CDGen_SetDirection 180
                CDGen_FowardDraw 0.4
            Case "H"
                CDGen_SetDirection - (Rnd * 20 - 10)
                CDGen_FowardDraw 1
                CDGen_MoveToMiddle 0, 50
                CDGen_SetDirection - 90
                CDGen_FowardDraw 1
                CDGen_MoveToMiddle 1, 100
                CDGen_SetDirection - 90
                CDGen_FowardDraw 0.5
                CDGen_MoveToMiddle 1, 100
                CDGen_SetDirection 180
                CDGen_FowardDraw 0.5
            Case "I"
                CDGen_SetDirection - (Rnd * 20 - 10)
                CDGen_FowardDraw 1
                CDGen_MoveToMiddle 0, 0
                CDGen_SetDirection - 90
                CDGen_FowardDraw 0.2
                CDGen_MoveToMiddle 0, 0
                CDGen_SetDirection 180
                CDGen_FowardDraw 0.2
                CDGen_MoveToMiddle 0, 100
                CDGen_FowardDraw 0.2
                CDGen_MoveToMiddle 0, 100
                CDGen_SetDirection 180
                CDGen_FowardDraw 0.2
            Case "J"
                CDGen_SetDirection - 90
                CDGen_FowardDraw 0.4
                CDGen_MoveToMiddle 0, 50
                CDGen_SetDirection 90
                CDGen_FowardDraw 0.6
                CDGen_SetDirection 60
                CDGen_FowardDraw 0.5
                CDGen_SetDirection 120
                CDGen_FowardDraw 0.5
            Case "K"
                CDGen_SetDirection - (Rnd * 20 - 10)
                CDGen_FowardDraw 1
                CDGen_MoveToMiddle 0, 50
                CDGen_SetDirection - 60
                CDGen_FowardDraw 0.6
                CDGen_MoveToMiddle 0, 50
                CDGen_SetDirection - 60
                CDGen_FowardDraw 0.6
            Case "L"
                CDGen_SetDirection - 90
                CDGen_FowardDraw 0.2
                CDGen_MoveToMiddle 0, 50
                CDGen_SetDirectionFormZero - (Rnd * 20 - 10)
                CDGen_FowardDraw 1
                CDGen_SetDirection - (110 - Rnd * 40)
                CDGen_FowardDraw 0.8
                CDGen_SetDirectionFormZero 0
                CDGen_FowardDraw - 0.3
            Case "M"
                CDGen_SetDirection 0
                CDGen_FowardDraw - 1
                CDGen_SetDirection - 30
                CDGen_FowardDraw 0.5
                CDGen_SetDirection 60
                CDGen_FowardDraw - 0.5
                CDGen_SetDirection - 30
                CDGen_FowardDraw 1
            Case "N"
                CDGen_SetDirection 0
                CDGen_FowardDraw - 1
                CDGen_SetDirection - 45
                CDGen_FowardDraw 1.4
                CDGen_SetDirection 45
                CDGen_FowardDraw - 1
            Case "O"
                CDGen_SetDirection - 60
                CDGen_FowardDraw - 0.7
                CDGen_SetDirection - 60
                CDGen_FowardDraw - 0.7
                CDGen_SetDirection 120
                CDGen_FowardDraw 1.5
                CDGen_SetDirection - 60
                CDGen_FowardDraw 0.7
                CDGen_SetDirection - 60
                CDGen_FowardDraw 0.7
                CDGen_Close 0
            Case "P"
                CDGen_SetDirection 0
                CDGen_FowardDraw - 1
                CDGen_SetDirection - 60
                CDGen_FowardDraw 0.5
                CDGen_SetDirection 60
                CDGen_FowardDraw 0.5
                CDGen_CloseToMiddle 0, 50
            Case "Q"
                CDGen_SetDirection - 60
                CDGen_FowardDraw - 0.7
                CDGen_SetDirection - 60
                CDGen_FowardDraw - 0.7
                CDGen_SetDirection 120
                CDGen_FowardDraw 1.5
                CDGen_SetDirection - 60
                CDGen_FowardDraw 0.7
                CDGen_SetDirection - 60
                CDGen_FowardDraw 0.7
                CDGen_Close 0
                CDGen_MoveToMiddle 4, 100
                CDGen_SetDirectionFormZero - 45
                CDGen_FowardDraw 0.7
                CDGen_MoveToMiddle 4, 100
                CDGen_SetDirection 180
                CDGen_FowardDraw 0.7
            Case "R"
                CDGen_SetDirection 0
                CDGen_FowardDraw - 1
                CDGen_SetDirection - 80
                CDGen_FowardDraw 0.5
                CDGen_SetDirection 60
                CDGen_FowardDraw 0.5
                CDGen_CloseToMiddle 0, 50
                CDGen_SetDirectionFormZero - 45
                CDGen_FowardDraw 0.7
            Case "S"
                CDGen_SetDirection - 45
                CDGen_FowardDraw - 0.5
                CDGen_SetDirection - 90
                CDGen_FowardDraw - 0.5
                CDGen_SetDirection 90
                CDGen_FowardDraw 1
                CDGen_SetDirection 90
                CDGen_FowardDraw 0.5
                CDGen_SetDirection 90
                CDGen_FowardDraw 0.5
            Case "T"
                CDGen_SetDirection - 90
                CDGen_FowardDraw 0.8
                CDGen_MoveToMiddle 0, 50
                CDGen_SetDirection 90
                CDGen_FowardDraw 1
                CDGen_MoveToMiddle 0, 0
                CDGen_SetDirection 30
                CDGen_FowardDraw 0.5
                CDGen_MoveToMiddle 0, 100
                CDGen_SetDirection - 60
                CDGen_FowardDraw 0.5
            Case "U"
                CDGen_FowardDraw 1
                CDGen_SetDirection - 60
                CDGen_FowardDraw 0.6
                CDGen_SetDirection - 60
                CDGen_FowardDraw 0.6
                CDGen_SetDirection - 60
                CDGen_FowardDraw 1
            Case "V"
                CDGen_SetDirection - 30
                CDGen_FowardDraw 1.5
                CDGen_SetDirection 60
                CDGen_FowardDraw - 1.5
            Case "W"
                CDGen_SetDirection - 30
                CDGen_FowardDraw 1.5
                CDGen_SetDirection 60
                CDGen_FowardDraw - 1
                CDGen_SetDirection - 60
                CDGen_FowardDraw 1
                CDGen_SetDirection 60
                CDGen_FowardDraw - 1.5
            Case "X"
                CDGen_SetDirection - 45
                CDGen_FowardDraw 1.4
                CDGen_MoveToMiddle 0, 50
                CDGen_SetDirection 90
                CDGen_FowardDraw 0.7
                CDGen_MoveToMiddle 0, 50
                CDGen_FowardDraw - 0.7
            Case "Y"
                CDGen_SetDirection - 30
                CDGen_FowardDraw 0.5
                CDGen_SetDirection 60
                CDGen_FowardDraw - 0.5
                CDGen_MoveToMiddle 0, 100
                CDGen_SetDirection - 30
                CDGen_FowardDraw 0.5
            Case "Z"
                CDGen_SetDirection - 90
                CDGen_FowardDraw 1
                CDGen_SetDirection - 45
                CDGen_FowardDraw - 1.4
                CDGen_SetDirection 45
                CDGen_FowardDraw 1
		End Select
		CDGen_Flush X0, Y0
	End Function
	Private Function CDGen_Blur()
		'对产生的位图进行柔化处理
		Dim I, J
		For J = 1 To nPixelHeight - 2
			For I = 1 To nCharCount * nPixelWidth - 2
				If Buf(J, I) = 0 Then
					If((Buf(J, I - 1) Or Buf(J + 1, I)) And 1) <> 0 Then
						'如果当前点是空白点，且上下左右四个点中有一个点是有色点，则该点做柔化处理
						Buf(J, I) = 2
					End If
				End If
			Next
		Next
	End Function
	Private Function CDGen_NoisyDot()
		'对产生的位图进行噪点处理
		Dim I, J, NoisyDot, CurDot
		For J = 0 To nPixelHeight - 1
			For I = 0 To nCharCount * nPixelWidth - 1
				If Buf(J, I) <> 0 Then
					NoisyDot = Int(Rnd * Rnd * nMaxSaturation)
					Select Case nColorNoisyDotOdds
						Case 0
							CurDot = nMaxSaturation
						Case 1
							CurDot = 0
						Case Else
							CurDot = NoisyDot
					End Select
					If Rnd < nColorNoisyDotOdds Then Buf(J, I) = CurDot Else Buf(J, I) = nMaxSaturation
				Else
					NoisyDot = Int(Rnd * nMaxSaturation)
					Select Case nBlankNoisyDotOdds
						Case 0
							CurDot = 0
						Case 1
							CurDot = nMaxSaturation
						Case Else
							CurDot = NoisyDot
					End Select
					If Rnd < nBlankNoisyDotOdds Then Buf(J, I) = CurDot Else Buf(J, I) = 0
				End If
			Next
		Next
	End Function
	Private Function CDGen()
		'生成位图阵列
		Dim I, Ch
		DigtalStr = ""
		CDGen_Clear
		Randomize
		For I = 0 To nCharCount - 1
			Ch = Mid(cCharSet, Int(Rnd * Len(cCharSet)) + 1, 1)
			DigtalStr = DigtalStr & Ch
			CDGen_Char Ch, I * nPixelWidth, 0
		Next
		CDGen_Blur
		CDGen_NoisyDot
	End Function
	Private Function HSBToRGB(vH, vS, vB)
		'将颜色值由HSB转换为RGB
		Dim aRGB(3), RGB1st, RGB2nd, RGB3rd
		Dim nH, nS, nB
		Dim lH, nF, nP, nQ, nT
		vH =(vH Mod 360)
		If vS > 100 Then
			vS = 100
		ElseIf vS < 0 Then
			vS = 0
		End If
		If vB > 100 Then
			vB = 100
		ElseIf vB < 0 Then
			vB = 0
		End If
		If vS > 0 Then
			nH = vH / 60
			nS = vS / 100
			nB = vB / 100
			lH = Int(nH)
			nF = nH - lH
			nP = nB * (1 - nS)
			nQ = nB * (1 - nS * nF)
			nT = nB * (1 - nS * (1 - nF))
			Select Case lH
				Case 0
					aRGB(0) = nB * 255
					aRGB(1) = nT * 255
					aRGB(2) = nP * 255
				Case 1
					aRGB(0) = nQ * 255
					aRGB(1) = nB * 255
					aRGB(2) = nP * 255
				Case 2
					aRGB(0) = nP * 255
					aRGB(1) = nB * 255
					aRGB(2) = nT * 255
				Case 3
					aRGB(0) = nP * 255
					aRGB(1) = nQ * 255
					aRGB(2) = nB * 255
				Case 4
					aRGB(0) = nT * 255
					aRGB(1) = nP * 255
					aRGB(2) = nB * 255
				Case 5
					aRGB(0) = nB * 255
					aRGB(1) = nP * 255
					aRGB(2) = nQ * 255
			End Select
		Else
			aRGB(0) =(vB * 255) / 100
			aRGB(1) = aRGB(0)
			aRGB(2) = aRGB(0)
		End If
		HSBToRGB = ChrB(Round(aRGB(2), 0)) & ChrB(Round(aRGB(1), 0)) & ChrB(Round(aRGB(0), 0))
	End Function
End Class
%>